home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk8 / asm / echo.asm < prev    next >
Assembly Source File  |  1995-03-18  |  8KB  |  197 lines

  1. ;
  2. ;   Yet another ECHO .. Jim Butterfield, 1988Apr2
  3. ;
  4. ;- This is a CLI command only.  Replaces ECHO 1.3 with NOLINE feature.
  5. ;- Usage: Echo [NOLINE] <string>     ..or.. <string> [NoLine]
  6. ;
  7. ;-  Quotes (") around the argument <string> are unnecessary
  8. ;    unless you wish to have leading spaces or to type NOLINE,
  9. ;    for example: Echo "    Never say NoLine"
  10. ;
  11. ;-  Asterisks are handled as follows:
  12. ;      *n or *N - outputs a Newline (linefeed);
  13. ;      *e or *E - outputs an Escape (chr${27});
  14. ;      *[anything else] prints the character after asterisk,
  15. ;                in particular:
  16. ;           ** - outputs an asterisk;
  17. ;           *" - outputs quotes (");
  18. ;      Example: Echo Input**Output 2 3 4
  19. ;     displays: Input*Output 2 3 4
  20. ; ===    Register Usage (* = used in system calls)  ===
  21. ;    *A0 - general pointer       *D0 - general byte buffer
  22. ;    *A1 - otherwise unused      *D1 - otherwise unused
  23. ;     A2 - output buf scan       *D2 - output buf pointer
  24. ;     A3 - input buf pointer     *D3 - output length
  25. ;     A4 - input scan ptr         D4 - LINK pointer
  26. ;     A5 - main scan ptr          D5 - NOLINE flag
  27. ;     A6 - library pointer        D6 - asterisk flag, buffer
  28. ;     A7 - gosh, I forget         D7 - DOS output handle
  29.  
  30. ;-- Symbolic equates:
  31. AbsExecBase equ $4        ; Loc of ptr to the
  32.                           ;   Exec library.
  33. LF          equ 10        ; Line Feed value.
  34. SPACE       equ 32        ; Space char
  35. CASEmask    equ %01011111 ; Mask to kill lower case.
  36. ;
  37.             xref _LVOOpenLibrary  ; These are Library routines referenced
  38.             xref _LVOCloseLibrary ; externally by this program.
  39.             xref _LVOOutput
  40.             xref _LVOWrite
  41.             xref _LVOInput
  42.             xref _LVORead
  43. ;
  44. ;  Save pointer and open DOS
  45. _main       moveq   #0,d5            ; clear noline flag
  46.             move.l  a0,a3            ; pointer, input-buffer
  47.             move.l  a0,a5            ; work pointer
  48.             lea     dosname(pc),a1
  49.             clr     d0               ;   Any version
  50.             move.l  AbsExecBase,a6
  51.             jsr     _LVOOpenLibrary(a6)  ;Open Dos library.
  52.             move.l  d0,a6            ; Remember dosbase ptr.
  53.             beq     quit
  54. ;
  55. ;-- Get CLI outhandle:
  56.             jsr _LVOOutput(a6)       ;   get CLI outhandle,
  57.             move.l d0,d7             ;   & then remember it.
  58. ; grab stack space
  59.             link    a4,#-$100
  60.             move.l  a4,d4
  61.             move.l  a7,a2            ;  pointer, output-buffer
  62. ;  Check for ? sequence
  63. qspace      move.l  a5,a4
  64.             cmp.b   #SPACE,(a5)+
  65.             beq.s   qspace
  66.             move.l  a4,a5
  67.             cmp.b   #$3F,(a4)+
  68.             bne.s   ljob
  69.             cmp.b   #LF,(a4)
  70.             bne.s   ljob
  71. ;  Do the prompt thing
  72.             lea     template(pc),a0
  73.             move.l  a0,d2
  74.             move.l  d7,d1
  75.             move.l  #templen,d3
  76.             jsr     _LVOWrite(a6)
  77.             jsr     _LVOInput(a6)
  78.             move.l  d0,d1
  79.             move.l  a2,a3            ;  switch input-buffer
  80.             move.l  a3,d2
  81.             move.l  #255,d3
  82.             jsr     _LVORead(a6)
  83. ;  Scan leading spaces and mebbe NOLINE
  84. ;
  85. ljob        move.l  a3,a5            ; input-buffer pointer
  86. lspace      move.l  a5,a4            ; first non-space
  87.             cmp.b   #SPACE,(a5)+
  88.             beq.s   lspace           ; space .. correct it
  89.             move.l  a4,a5
  90.             tst.b   d5               ; if we've found NOLINE..
  91.             bne.s   nonoline1        ;   ..don't search again
  92. ; search for NOLINE <space> at start
  93.             lea     nolnstr(pc),a0
  94. nolinecklp  move.b  (a4)+,d0         ; text char
  95.             andi.b  #CASEmask,d0
  96.             cmp.b   (a0)+,d0         ; NOLINE mask char
  97.             bne.s   nonoline1
  98.             tst.b   d0               ; <space> becomes $0
  99.             bne.s   nolinecklp       ; if not space, back
  100. ; found NOLINE <space>
  101.             moveq   #1,d5            ; set NOLINE flag
  102.             move.l  a4,a5
  103.             bra.s   lspace           ; trim extra spaces
  104. ; scan to end of input, trim end spaces            
  105. nonoline1   move.l  a5,a4
  106. findend     cmpi.b  #LF,(a4)+        ; search for LF
  107.             bne.s   findend
  108. espace      move.b  #0,-(a4)         ; change end to $0
  109.             move.l  a4,a0
  110.             cmp.b   #SPACE,-(a0)
  111.             beq.s   espace           ; back through spaces
  112.             tst.b   d5               ; if we've found NOLINE..
  113.             bne.s   nonoline2        ;  ..don't search again
  114. ; search for <space>NOLINE at end
  115.             lea     nolnstrend(pc),a0
  116. nolckloop   move.b  -(a4),d0         ; text char
  117.             andi.b  #CASEmask,d0
  118.             cmp.b   -(a0),d0         ; NOLINE mask char
  119.             bne.s   nonoline2
  120.             tst.b   d0               ; <space> has become $0
  121.             bne.s   nolckloop        ; not space, try more.
  122.             moveq   #1,d5            ; set NOLINE flag.
  123.             addq.l  #1,a4
  124.             bra.s   espace           ; back to kill space(s).
  125. ;
  126. ;-- Start the argument line scanning process:
  127. nonoline2   clr.l   d3               ; Clear output-chars count.
  128.             clr.b   d6               ; Clear asterisk flag.
  129.             move.l  a2,d2
  130. ;
  131. ;-- Make new output line from argument line:
  132. scan        move.b  (a5)+,d0         ; Get argument char.
  133.             beq     exit             ; Zero means we're finsihed.
  134. ;
  135. ;-- Check special chars flag:
  136.             tst.b   d6               ; Check asterisk flag.
  137.             beq.s   noastrsk         ; No asterisk?  Skip.
  138. ;
  139. ;-- Handle asterisk-plus-char:
  140.             move.b  d0,d6
  141.             andi.b  #CASEmask,d6     ; Kill lower case.
  142.             cmpi.b  #69,d6           ; Test for E
  143.             bne.s   try2
  144.             move.b  #27,d0           ; E, substitute ESC
  145.  
  146. try2        cmpi.b  #78,d6           ; Test for N
  147.             bne.s   putinbuf
  148.             move.b  #LF,d0           ; N, substitute Newline
  149. ;
  150. ;-- Check for quote:
  151. noastrsk    cmpi.b  #'"',d0          ; If char is quote,
  152.             beq.s   scan             ;          skip it.
  153. ;
  154. ;-- Check for asterisk:
  155.             moveq   #1,d6
  156.             cmpi.b  #'*',d0          ; Is it '*'?
  157.             beq.s   scan             ; Yes, log and get next char
  158. ;
  159. ;-- Put char in buffer:
  160. putinbuf    clr.b   d6               ; Clear Asterisk flag
  161.             move.b  d0,(a2)+         ; Put char to output buffer.
  162.             addq.b  #1,d3            ; Increment outchar count.
  163.             bra.s   scan             ; Go for more input.
  164. ;
  165. ;-- After looking at all argument chars:
  166. exit        tst.b   d5               ; Check NOLINE flag.
  167.             bne.s   nolf
  168.             move.b  #LF,(a2)+        ; If it's 0, put a linefeed at end.
  169.             addq.b  #1,d3            ;   & increment count to handle it.
  170. nolf        tst.b   d3
  171.             beq     close
  172. ; D2 and D3 already contain buffer address and size
  173.             move.l  d7,d1            ; Outhandle
  174.             jsr     _LVOWrite(a6)    ; Print it!
  175. ;
  176. ;-- Unlink and close opened libraries:
  177. close       move.l  d4,a4
  178.             unlk    a4
  179.             move.l  a6,a1            ; DOSBase to A1
  180.             move.l  AbsExecBase,a6   ;   Exec library...
  181.             jsr     _LVOCloseLibrary(a6)    ;   close Dos library.
  182. quit        rts                      ; Return control to CLI.
  183. ;
  184. ;-- Dos Library name:
  185. dosname dc.b 'dos.library',0  ;name of  Dos library
  186. ;-- NoLine keyword
  187.             dc.b 0
  188. nolnstr     dc.b 'NOLINE'
  189. nolnstrend  equ  *
  190.             dc.b 0
  191. ;-- Template string:
  192. template dc.b 'STRING,NOLINE/S: '
  193. endtemp:
  194. templen  EQU   endtemp-template
  195.  
  196.    end
  197.